package com.example.service;

import com.example.entity.Grid;
import com.example.entity.GridReservation;
import com.example.mapper.GridReservationMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*  位置预订的逻辑层
**/
@Service
@RequiredArgsConstructor
public class GridReservationService {

   private final GridReservationMapper gridReservationMapper;

   /**
   * 增
   **/
   public void add(GridReservation gridReservation) {
       gridReservationMapper.insert(gridReservation);
   }

   /**
   * 删
   **/
   public void deleteById(Integer id) {
       gridReservationMapper.deleteById(id);
   }

   /**
   * 批量删除
   **/
   public void deleteBatch(List<Integer> ids) {
       for (Integer id : ids) {
       gridReservationMapper.deleteById(id);
       }
   }

   /**
   * 改
   **/
   public void updateById(GridReservation gridReservation) {
       gridReservationMapper.updateById(gridReservation);
   }

   /**
   * 根据ID查询
   **/
   public GridReservation selectById(Integer id) {
       return gridReservationMapper.selectById(id);
   }

   /**
   * 查询所有
   **/
   public List<GridReservation> selectAll(GridReservation gridReservation) {
       return gridReservationMapper.selectAll(gridReservation);
   }

   /**
   * 分页查询
   **/
   public PageInfo<GridReservation> selectPage(GridReservation gridReservation, Integer pageNum, Integer pageSize) {
       PageHelper.startPage(pageNum, pageSize);
       List<GridReservation> list = gridReservationMapper.selectAll(gridReservation);
       return PageInfo.of(list);
   }

    public boolean selectByGId(Integer gridId) {
       return gridReservationMapper.selectByGId(gridId) != null;
    }
}